package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class DvdCollection here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DvdCollection
{
    //
    private ArrayList<Dvd> dvd;
    private static DvdCollection instance;
    
    private DvdCollection()
    {
        dvd = new ArrayList<Dvd>();
    }
    
    public static DvdCollection getInstance()
    {
        if(instance == null)
        {
            instance = new DvdCollection();
        }
        return instance;
    }
    
    public void addDvd(Dvd oneDvd)
    {
        dvd.add(oneDvd);
    }
    
    public String getDvd(long id, int number)
    {
        for(Dvd d : dvd)
        {
            if(id == d.getId())
            {
                if(number == 1)
                {
                    return d.getTitle();
                }
                else if(number == 2)
                {
                    return d.getArtist();
                }
                else if(number == 3)
                {
                    return d.getReleaseDate();
                }
            }
        }
        return null;
    }
    
    public void deleteDvd(long id)
    {
        for(int i = 0; i < dvd.size(); i++)
        {
            if(id == dvd.get(i).getId())
            {
                dvd.remove(i);
            }
        }
    }
    
    public void updateDvd(long id, int number, String arg)
    {
        for(Dvd d : dvd)
        {
            if(id == d.getId())
            {
                if(number == 1)
                {
                    d.setTitle(arg);
                }
                else if(number == 2)
                {
                    d.setArtist(arg);
                }
                else if(number == 3)
                {
                    d.setReleaseDate(arg);
                }
            }            
        }
    }
    
    public void createCopy(long id, long serienr, String date, String price)
    {
        for(Dvd d : dvd)
        {
            if(id == d.getId())
            {
                Eksemplar e = new Eksemplar(serienr, date, price);
                d.addEksemplar(e);
            }
        }
    }
    
    public ArrayList listAllCopies()
    {
        for(Dvd d : dvd)
        {
            return d.listAllCopies();
        }
        return null;
    }
    
    public ArrayList listAllDvds()
    {
        return dvd;
    }
    
    public long getID(long id)
    {
        for(Dvd d : dvd)
        {
            if(id == d.getId())
            {
                return d.getId();
            }
        }
        return 0;
    }
}
